package pers.feng1240.blog.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * 分页辅助类
 */
public class PageHelper {

	private static int pageSize = 12;	//后台每页显示数量
	private static int forePageSize = 6;   //前台每页显示数量
	
	/*
	 * 封装向数据访问层传递的数据
	 * @param pageIndex 获取第pageIndex页数据
	 */
	public static Map<String, Object> selObj(int pageIndex){       //后台
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("objectStart", getPageSize() *(pageIndex-1)); //第pageIndex页第一条数据
		map.put("offset", getPageSize());		 //第pageIndex页最后一条数据
		return map;
	}
	
	public static Map<String, Object> selObjFore(int pageIndex){   //首页
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("objectStart", getForePageSize() *(pageIndex-1)); //第pageIndex页第一条数据
        map.put("offset", getForePageSize());        //第pageIndex页最后一条数据
        System.out.println(getForePageSize() *(pageIndex-1));
        System.out.println(getForePageSize());
        return map;
    }
	
	
	 public static Map<String, Object> selObjTag(int pageIndex,int id) {
	     Map<String,Object> map = new HashMap<String,Object>();
         map.put("objectStart", getForePageSize() *(pageIndex-1)); //第pageIndex页第一条数据
         map.put("offset", getForePageSize());        //第pageIndex页最后一条数据
         map.put("id", id);        //标签id
         return map;
	 }
	    
	    
	/*
	 * 当前页判断转化
	 * @param pageIndex 当前页
	 */
	public static int pageIndex(String pageIndex){
		if(pageIndex==null){
			//页面初始化
			int i = 1;
			return i;
		}else{
			return Integer.parseInt(pageIndex);
		}
	}
	
	/*
	 * 计算总页数
	 * @param count 数据总数
	 */
	public static int pageSize(int count){     //后台
		    return (count%pageSize==0)?count/pageSize:(count/pageSize+1);   
	}
	
	public static int forePageSize(int count){ //首页
        return (count%forePageSize==0)?count/forePageSize:(count/forePageSize+1);   
	}

	/*
	 * getter setter
	 */
	public static int getPageSize() {
		return pageSize;
	}

	public static void setPageSize(int pageSize) {
		PageHelper.pageSize = pageSize;
	}

    
    public static int getForePageSize() {
        return forePageSize;
    }

    
    public static void setForePageSize(int forePageSize) {
        PageHelper.forePageSize = forePageSize;
    }

   
}
